package com.easy.frame.base.service.rabbit;

import com.easy.frame.base.basic.pojo.SysExceptionLog;
import com.easy.frame.common.redis.SpringUtil;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

/**
 * rabbit操作工具类
 *
 * @author zzf
 * @date 2021/1/7 18:55
 */
public class RabbitUtil {

    /**
     * 发送异常持久化消息
     *
     * @param exceptionLog 异常日志对象
     */
    public static void sendException(SysExceptionLog exceptionLog) {
        RabbitServer.I.getInstance().convertAndSend(
                RabbitConstants.Exchange.EXCEPTION_HANDLER,
                RabbitConstants.Queue.EXCEPTION_HANDLER,
                exceptionLog
        );
    }

    public enum RabbitServer {
        I;
        private RabbitTemplate template;

        RabbitServer() {
            template = SpringUtil.getBean(RabbitTemplate.class);
        }

        public RabbitTemplate getInstance() {
            return template;
        }

    }
}
